home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / go2.arc / GO.BAS next >
BASIC Source File  |  1989-07-21  |  6KB  |  255 lines

  1. '$INCLUDE: 'QB.BI'
  2.  
  3. DEFINT A-Z
  4.  
  5. TYPE DTAType
  6.     reserved  AS STRING * 21
  7.     attrib    AS STRING * 1
  8.     WriteTime AS INTEGER
  9.     WriteDate AS INTEGER
  10.     Size      AS LONG
  11.     FileName  AS STRING * 13
  12. END TYPE
  13.  
  14. DECLARE SUB ParseCommandLine ()
  15. DECLARE SUB Help ()
  16. DECLARE SUB Done ()
  17. DECLARE SUB TestDir ()
  18. DECLARE FUNCTION GetDrive% ()
  19. DECLARE SUB SetDrive (Drive%)
  20. DECLARE FUNCTION GetCurrDir$ ()
  21. DECLARE FUNCTION DOSFindFirst% (Spec$, attrib%)
  22. DECLARE FUNCTION DOSFindNext% ()
  23. DECLARE SUB SetDTA (DTA AS DTAType)
  24.  
  25. CONST FALSE = 0
  26. CONST TRUE = NOT FALSE
  27.  
  28. CLEAR , , 3000
  29.  
  30. DIM SHARED FileSearch, DirSearch
  31. DIM SHARED OrigDrive, OrigDir$
  32. DIM SHARED SearchDrive
  33. DIM SHARED DIRSearchString$, DIRSearchLength
  34. DIM SHARED FileSearchString$
  35. DIM SHARED ResetDrive, ResetDir
  36. DIM SHARED ParamCount, Param$(10)
  37. DIM SHARED InRegs AS RegType, OutRegs AS RegType
  38. DIM SHARED InRegsX AS RegTypeX, OutRegsX AS RegTypeX
  39.  
  40. FileSearch = TRUE
  41. DirSearch = TRUE
  42.  
  43. ResetDrive = FALSE
  44. ResetDir = FALSE
  45.  
  46. CONST NORMAL = 0
  47. CONST SUBDIR = &H10
  48.  
  49. '++++++++++++++++++++++++++++++++++++
  50. '  Program begins here
  51. '++++++++++++++++++++++++++++++++++++
  52.  
  53. ParseCommandLine
  54. IF ParamCount < 1 OR ParamCount > 2 THEN
  55.     Help
  56.     END
  57. END IF
  58.  
  59. OrigDrive = GetDrive
  60. OrigDir$ = GetCurrDir$
  61.  
  62. IF ParamCount = 2 THEN
  63.     IF Param$(2) = "-F" OR Param$(2) = "/F" THEN
  64.         DirSearch = FALSE
  65.     ELSE
  66.         Help
  67.     END IF
  68. END IF
  69.  
  70. SearchString$ = Param$(1)
  71.  
  72. IF MID$(SearchString$, 2, 1) = ":" THEN
  73.     NewDrive = ASC(LEFT$(SearchString$, 1)) - ASC("A")
  74.     SetDrive (NewDrive)
  75.     ResetDrive = TRUE
  76.     SearchString$ = MID$(SearchString$, 3)
  77. END IF
  78.  
  79. IF LEFT$(SearchString$, 1) = "\" THEN
  80.     SearchString$ = MID$(SearchString$, 2)
  81.     FileSearch = FALSE
  82. END IF
  83.  
  84. IF INSTR(SearchString$, "?") OR INSTR(SearchString$, "*") THEN
  85.     DirSearch = FALSE
  86. END IF
  87.  
  88. IF DirSearch THEN
  89.     DIRSearchString$ = SearchString$
  90.     DIRSearchLength = LEN(DIRSearchString$)
  91. END IF
  92.  
  93. IF FileSearch THEN
  94.     FileSearchString$ = SearchString$
  95.     IF INSTR(FileSearchString$, ".") = 0 THEN
  96.         FileSearchString$ = FileSearchString$ + ".*"
  97.     END IF
  98. END IF
  99.  
  100. IF DirSearch OR FileSearch THEN
  101.     CHDIR ("\")
  102.     TestDir
  103.     ResetDir = TRUE
  104.     Done
  105. ELSE
  106.     Help
  107. END IF
  108. END
  109.  
  110. SUB ParseCommandLine
  111.     temp$ = LTRIM$(RTRIM$(UCASE$(COMMAND$))) + " "
  112.     ParamCount = 0
  113.     DO WHILE LEN(temp$) > 1
  114.         ParamCount = ParamCount + 1
  115.         Param$(ParamCount) = LEFT$(temp$, INSTR(temp$, " ") - 1)
  116.         temp$ = MID$(temp$, INSTR(temp$, " ") + 1)
  117.     LOOP
  118. END SUB
  119.  
  120. SUB Help
  121.     PRINT "GO moves you quickly from one subdirectory to another"
  122.     PRINT "Syntax:"
  123.     PRINT "       GO [d:][\]pathname [-F]"
  124.     PRINT "          the pathname can be either the name of a directory or"
  125.     PRINT "          the name of a file.  It may contain wild cards."
  126.     PRINT
  127.     PRINT "          If 'd:' is included, drive 'd:' will be used instead"
  128.     PRINT "          of the current default drive."
  129.     PRINT
  130.     PRINT "          If '\' is included at the beginning of the pathname,"
  131.     PRINT "          only subdirectory names will be searched."
  132.     PRINT
  133.     PRINT "          If '-F' or '/F' is included, or if pathname includes"
  134.     PRINT "          wild card symbols, only file names will be searched."
  135.     PRINT
  136.     PRINT "          Normally, both file names and subdirectory names are"
  137.     PRINT "          searched to match the specified pathname."
  138.     PRINT
  139.     END
  140. END SUB
  141.  
  142. SUB Done
  143.     IF ResetDir THEN
  144.         PRINT "   Requested subdirectory not found" + CHR$(7)
  145.         CHDIR (OrigDir$)
  146.     ELSE
  147.         PRINT "   New Directory: "; GetCurrDir$
  148.     END IF
  149.  
  150.     IF ResetDrive THEN
  151.         SetDrive (OrigDrive)
  152.     END IF
  153.     END
  154. END SUB
  155.  
  156. SUB TestDir
  157.     DIM LocalDTA AS DTAType
  158.     CALL SetDTA(LocalDTA)
  159.     
  160.     CurrentDir$ = GetCurrDir$
  161.     IF DirSearch AND LEN(CurrentDir$) >= DIRSearchLength THEN
  162.         IF RIGHT$(CurrentDir$, DIRSearchLength) = DIRSearchString$ THEN
  163.             Done
  164.         END IF
  165.     END IF
  166.  
  167.     IF FileSearch THEN
  168.         IF DOSFindFirst(FileSearchString$, NORMAL) THEN
  169.             Done
  170.         END IF
  171.     END IF
  172.  
  173.     IF DOSFindFirst("*.*", SUBDIR) THEN
  174.         IF LocalDTA.attrib$ = CHR$(SUBDIR) AND LEFT$(LocalDTA.FileName$, 1) <> "." THEN
  175.             CHDIR (LocalDTA.FileName$)
  176.             TestDir
  177.             CALL SetDTA(LocalDTA)
  178.             CHDIR (CurrentDir$)
  179.         END IF
  180.  
  181.         DO WHILE DOSFindNext
  182.             IF LocalDTA.attrib$ = CHR$(SUBDIR) AND LEFT$(LocalDTA.FileName$, 1) <> "." THEN
  183.                 CHDIR (LocalDTA.FileName$)
  184.                 TestDir
  185.                 CALL SetDTA(LocalDTA)
  186.                 CHDIR (CurrentDir$)
  187.             END IF
  188.         LOOP
  189.     END IF
  190. END SUB
  191.  
  192. '++++++++++++++++++++++++++++++++++++
  193. '  DOS Interface Functions
  194. '++++++++++++++++++++++++++++++++++++
  195.  
  196. FUNCTION DOSFindFirst (Spec$, attrib%)
  197.         ' Calls DOS to find directory entry with attribute attrib%
  198.         ' and file name matching Spec$.  Returns TRUE if entry is
  199.         ' found, else returns FALSE
  200.     temp$ = Spec$ + CHR$(0)
  201.     InRegsX.ax = &H4E00
  202.     InRegsX.cx = attrib
  203.     InRegsX.ds = VARSEG(temp$)
  204.     InRegsX.dx = SADD(temp$)
  205.     CALL INTERRUPTX(&H21, InRegsX, OutRegsX)
  206.     DOSFindFirst = ((OutRegsX.flags AND &H1) = 0)
  207. END FUNCTION
  208.  
  209. FUNCTION DOSFindNext
  210.         'Calls DOS to see if there is another entry that meets the
  211.         'last specification sent to DOSFindFirst.  If so, returns TRUE;
  212.         'else returns FALSE
  213.     InRegs.ax = &H4F00
  214.     CALL INTERRUPT(&H21, InRegs, OutRegs)
  215.     DOSFindNext = ((OutRegs.flags AND &H1) = 0)
  216. END FUNCTION
  217.  
  218. FUNCTION GetCurrDir$
  219.         ' Calls DOS to get the name of the current default subdirectory.
  220.         ' Returns the directory as a string in the form  \name.....
  221.         ' so that the same string can be used with CHDIR
  222.     DIM temp AS STRING * 64
  223.     InRegsX.ax = &H4700
  224.     InRegsX.dx = 0
  225.     InRegsX.ds = VARSEG(temp$)
  226.     InRegsX.si = VARPTR(temp$)
  227.     CALL INTERRUPTX(&H21, InRegsX, OutRegsX)
  228.     GetCurrDir$ = "\" + LEFT$(temp$, INSTR(temp$, CHR$(0)) - 1)
  229. END FUNCTION
  230.  
  231. FUNCTION GetDrive%
  232.         'Calls DOS to get current drive letter.  Returns drive as
  233.         'an integer (A = 0, B = 1, etc.)
  234.     InRegs.ax = &H1900
  235.     CALL INTERRUPT(&H21, InRegs, OutRegs)
  236.     GetDrive = OutRegs.ax AND 255
  237. END FUNCTION
  238.  
  239. SUB SetDrive (Drive)
  240.         ' Calls DOS to change the current default drive
  241.     InRegs.ax = &HE00
  242.     InRegs.dx = Drive
  243.     CALL INTERRUPT(&H21, InRegs, OutRegs)
  244. END SUB
  245.  
  246. SUB SetDTA (DTA AS DTAType)
  247.         ' Calls DOS to set the current disk transfer area (DTA) for use
  248.         ' by DOSFindFirst and DOSFindNext
  249.     InRegsX.ax = &H1A00
  250.     InRegsX.ds = VARSEG(DTA)
  251.     InRegsX.dx = VARPTR(DTA)
  252.     CALL INTERRUPTX(&H21, InRegsX, OutRegsX)
  253. END SUB
  254.  
  255.